
const path = require('path');
const fs = require('fs');
const Router = require('koa-router');
const koaCompose = require("koa-compose");
const router = new Router();

const route = require('../route');

module.exports = () => {
    route.forEach((singRoute, index) => {
        let { match, controller,method = "get" } = singRoute;
        let controllerList = controller.split('.');
        let FunName=controllerList[0];
        let currentPath=path.resolve(__dirname, "../controllers/"+FunName);
        let routeFuns = require(currentPath);
        let currentFun=routeFuns[controllerList[1]];
        router[method.toLowerCase()](singRoute.match, currentFun)
    });

    return koaCompose([router.routes(), router.allowedMethods()]);
};
